#ifndef OFFUNCTIONS_H_
#define OFFUNCTIONS_H_

/*******************************************************************************
OFFunctions.h

===============================================================================
Copyright (c) 2010, Centeye, Inc.
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
    * Redistributions of source code must retain the above copyright
      notice, this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright
      notice, this list of conditions and the following disclaimer in the
      documentation and/or other materials provided with the distribution.
    * Neither the name of Centeye, Inc. nor the
      names of its contributors may be used to endorse or promote products
      derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL CENTEYE, INC. BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
===============================================================================

These are the basic optical flow functions. Ideally these will be called by
the firmware module.

Origin:
Adapted from OFSupport by Travis Young, which was adapted from libraries by
Craig Neely

Change Log:
2010 May 21, Friday, birth
2010 August 9, Monday, documentation
******************************************************************************/

#include <stdint.h>
#include "F64PlusInterface.h"
#include "ApplicationPrototype.h"

// OF processing modes
#define	IMAGEOF_MODE_LK_XY			0		// image interpolation
#define	IMAGEOF_MODE_LK_X			1		// image interpolation
#define	IMAGEOF_MODE_LK_Y			2		// image interpolation
#define	IMAGEOF_MODE_IIA_XY			3		// Lucas-Kanade
#define	IMAGEOF_MODE_IIA_X			4		// Lucas-Kanade
#define	IMAGEOF_MODE_IIA_Y			5		// Lucas-Kanade
#define	IMAGEOF_MODE_DEFAULT		IMAGEOF_MODE_LK_XY

// OF variables
int ImageOFMode;
float of_scale;  // This is to be updated whenever the byte is changed by calling the macro below
#define of_scale_byte state_vars.read[11] // the byte that is set, which is scaled internally
#define of_scale_assign() of_scale = (((float) of_scale_byte)*2) // change factors here
//int of_count;
int of_speed;
int SearchDist;	

// basic optical flow values
signed char OFX;
signed char OFY;

// cumulative optical flow e.g. odometry
signed int CX,CY;

// running averaged optical flow
float ROFX,ROFY;
//unsigned char rof_shift; // number of times to shift for computing ROF- run-time parameter
#define rof_shift state_vars.read[5]	// moved here
//unsigned char OF_deadzone; // minimum optical flow magnitude for adding to cumulative- run-time parameter
#define OF_deadzone state_vars.read[3]	// moved here

void IIA2(const unsigned char *const X1, const unsigned char *const X2);

void Pix_HPF8(unsigned char *Iin, unsigned char *Ilp, unsigned char *Ihp, unsigned char skipcnt);
void Pix_HPF(unsigned char *const Iin, signed int *const Ilp, const unsigned char shift);
void AddFPN(unsigned char *const X, const unsigned char strength);
void SubtractCalMask(unsigned char *const Iin);


#endif /*OFFUNCTIONS_H_*/
